/*******************************************************************************
 * The MOSES project, model based software engineering of networked embedded systems.
 * 
 * Copyright (C) 2010-2013, University of Applied Sciences Wildau,
 * Telematics Research Group, http://www.tm.th-wildau.de/research-group
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses>.
 * 
 * Contributors:
 *     University of Applied Sciences Wildau - initial API and implementation
 * 
 * If you are interested in a commercial license please contact us via 
 * e-mail: ralf.vandenhouten@th-wildau.de.
 ******************************************************************************/
package de.thwildau.tm.moses.abnf.io;

import java.io.IOException;
import java.nio.ByteBuffer;

/**
 * A {@code ParseException} is an exception that indicates that the data in a stream cannot be parsed to a
 * specific object. The reading process should abort to create the current object. The
 * {@link #getLastBuffer()} returns the last sequences of bytes that were read from the stream. After catching
 * this exception this byte buffer can be further instructed to check if the rest of the data is valid.
 * <p>
 * This exception should not be thrown if an underlying error has occurred.
 * </p>
 * 
 * @author Thomas Kistel
 * @version $Revision: 762 $
 */
public class ParseException extends IOException {

    private static final long serialVersionUID = -6820838863737002831L;

    private ByteBuffer lastBuffer;


    /**
     * Constructs an {@code ParseException} with the specified detail message and the last buffer. The
     * {@code lastBuffer} may be empty, but must not be {@code null}.
     * 
     * @param message The detail message (which is saved for later retrieval by the {@link #getMessage()}
     *        method)
     * @param lastBuffer the buffer of the last read sequences of bytes
     */
    public ParseException(String message, ByteBuffer lastBuffer) {
        super(message);
        this.lastBuffer = lastBuffer;
    }

    /**
     * Returns the buffer of the last read sequences of bytes. The buffer may be empty, but 
     * never {@code null}.
     * 
     * @return the buffer of the last read sequences of bytes
     */
    public ByteBuffer getLastBuffer() {
        return lastBuffer;
    }
}
